from enum import Enum
from app.serve.wtrees.base import BaseModel
from sqlalchemy import Column, Index, Integer, String, SmallInteger, text


class GroupModel(BaseModel):
    __tablename__ = "wtrees_group"
    __table_args__ = (Index("name_del", "name", "delete_time", unique=True),)

    class GroupEnum(Enum):
        ROOT = 1  # "超级管理员"
        admin = 2  # 管理员
        USER = 3  # 用户

    id = Column(Integer(), primary_key=True)
    name = Column(String(60), nullable=False, comment="用户组名称")
    info = Column(String(255), comment="用户组详情内容")
    level = Column(
        SmallInteger(),
        nullable=False,
        server_default=text(str(GroupEnum.USER.value))
    )

    def get_info(self):
        return {
            "id": self.id,
            "name": self.name,
            "info": self.info,
            "create_time": self.create_time,
        }
